package com.bawei.module_demo.query

import android.os.Bundle
import android.text.Editable
import android.text.TextWatcher
import android.util.Log
import android.view.View
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import androidx.lifecycle.lifecycleScope
import androidx.recyclerview.widget.LinearLayoutManager
import com.bawei.module_demo.R
import com.bawei.module_demo.databinding.ActivityQueryBinding
import kotlinx.coroutines.launch

class QueryActivity : AppCompatActivity() {

    private lateinit var binding: ActivityQueryBinding
    private lateinit var mAdapter:QueryAdapter
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        binding = ActivityQueryBinding.inflate(layoutInflater)
        setContentView(binding.root)
        val list = mutableListOf(QueryItem("时尚"),
            QueryItem("gg"),
            QueryItem("ss"),
            QueryItem("nba"),
            QueryItem("gege")
        )
        val query = binding.searchInput.text.toString()
        fun getQueryContent(){
            Log.d("TAG", "getQueryContent: $list")
        }

        lifecycleScope.launch {

        }
        mAdapter = QueryAdapter(list)
        binding.clearButton.setOnClickListener { binding.searchInput.text = null }
        binding.searchInput.addTextChangedListener(object :TextWatcher{
            override fun beforeTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {

            }

            override fun onTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {

            }

            override fun afterTextChanged(p0: Editable?) {
                binding.clearButton.visibility= if(p0.isNullOrEmpty()) View.GONE else View.VISIBLE
            }
        })
        binding.searchResults.adapter = mAdapter
        binding.searchResults.layoutManager = LinearLayoutManager(this,LinearLayoutManager.HORIZONTAL,false)


    }
}